---
category: Layout
created: '2019-11-16'
description: Create a sidebar with CSS flexbox
keywords: css flexbox, css layout, css sidebar
thumbnail: /assets/css-layout/thumbnails/sidebar.png
title: Sidebar
---

## HTML

```html index.html
<div class="sidebar">
    <!-- Sidebar -->
    <aside class="sidebar__sidebar">...</aside>

    <!-- Main -->
    <main class="sidebar__main">...</main>
</div>
```

## CSS

```css styles.css
.sidebar {
    display: flex;
}

.sidebar__sidebar {
    width: 30%;
}

.sidebar__main {
    /* Take the remaining width */
    flex: 1;

    /* Make it scrollable */
    overflow: auto;
}
```

<Playground>
```css placeholders.css hidden
.lines {
    padding: 0.25rem 0;
    width: 100%;
    align-items: center;
    display: flex;
    justify-content: center;
    flex-direction: column;
}
.line {
    background: #d1d5db;
    height: 1px;
    margin-bottom: 0.25rem;
}
.line.line--20 {
    width: 20%;
}
.line.line--40 {
    width: 40%;
}
.line.line--60 {
    width: 60%;
}
.line.line--80 {
    width: 80%;
}
.line.line--100 {
    width: 100%;
}
```

```css styles.css hidden
body {
    height: 24rem;
}

.sidebar {
    display: flex;

    /* Demo */
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    height: 100%;
    width: 100%;
}

.sidebar__sidebar {
    border-right: 1px solid #d1d5db;
    width: 30%;

    /* Demo */
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.sidebar__main {
    /* Take the remaining width */
    flex: 1;

    /* Make it scrollable */
    overflow: auto;
}
```

```html index.html hidden
<div class="sidebar">
    <div class="sidebar__sidebar">
        <div class="lines">
            <div class="line line--80"></div>
            <div class="line line--40"></div>
            <div class="line line--100"></div>
            <div class="line line--60"></div>
            <div class="line line--20"></div>
        </div>
    </div>
    <div class="sidebar__main">
        <div class="lines">
            <div class="line line--80"></div>
            <div class="line line--40"></div>
            <div class="line line--100"></div>
            <div class="line line--60"></div>
            <div class="line line--20"></div>
        </div>
    </div>
</div>
```
</Playground>
